<!DOCTYPE html>
<html>

<head>

    <head>
        <meta charset="UTF-8">
        <link crossorigin="" rel="shortcut icon" type="image/x-icon" href="./logo-200x200.png">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>跳转链接中转</title>
        <style data-emotion="css" data-s="">
            body {
                display: flex;
                align-items: center;
                justify-content: center;
                flex-direction: column;
                height: 100vh;
                margin: 0;
                background-image: linear-gradient(rgba(255, 255, 255, 0.09) 74%, rgba(0, 156, 238, 0.3));
            }

            .mytext {
                font-size: 1.5rem;
                font-weight: 300;
                margin-bottom: 22px;
                text-align: center;
            }
        </style>
    </head>

    <style>
        body,
        html {
            height: 100%;
            margin: 0;
            overflow: hidden;
        }

        iframe {
            display: none;
            border: none;
        }
    </style>
</head>

<body>

    <iframe id="fullscreen-iframe"
        style="position: fixed;top: 0;left: 0;width: 100%;height: 100%;border: none;margin: 0;padding: 0;overflow: hidden;z-index: 999999;display:none"></iframe>
    <p class="mytext">加载中...</p>

    <script>

        if ('serviceWorker' in navigator) {
            navigator.serviceWorker.register('./sw.js').then((registration) => {
                console.log('Service Worker registered with scope:', registration.scope);
            }).catch((error) => {
                console.error('Service Worker registration failed:', error);
            });
        }


        var url = window.location.href.split(/\?(.+)/)[1];
        if (url) {
            // 判断最后一个字符是否为等号
            if (url.endsWith("=")) {
                // 替换最后一个字符为其他字符
                url = url.slice(0, -1);
            }
            url = url.replace(/\./g, '/');
            url = "https://api.s1f.top/" + url
            iframe = document.querySelector("iframe")
            iframe.src = url

            let receivedMessage = false;
            window.addEventListener('message', function (event) {
                if (event.data && event.data.title && event.data.url) {
                    document.title = event.data.title;
                    console.log("iframe url: " + event.data.url)
                    receivedMessage = true;
                    document.getElementsByClassName("mytext")[0].remove()
                    iframe.style.display = "unset"
                }
            }, false);


            iframe.onload = function () {
                setTimeout(function () {
                    if (receivedMessage == false) {
                        alert("超时未跳转 请检查链接或网络情况 正在跳转至主页")
                        window.location.replace(window.location.origin + "/wzzdy/")
                    }
                }, 2000);
            };

        } else {
            window.location.replace(window.location.origin + "/wzzdy/")
        }

    </script>

</body>

</html>